import { getProductsInfo } from '@/api/common'
export default function() {
    return {
        data() {
            return {
                selectLoading: false,
                productsList: []
            }
        },
        methods: {
            async remoteGetProducts(query){
                this.selectLoading = true;
                const res = await getProductsInfo(query);
                this.selectLoading = false;
                if(res.data.code === 0){
                    let tempArr = [];
                    res.data.data.forEach(item => {
                        tempArr.push({
                            label: item.name,
                            value: item.id,
                            upsName: item.upsName,
                            businessName: item.businessName
                        });
                    });
                    this.productsList = tempArr;
                }else {
                    this.productsList = [];
                }          
            },
            async focusGetProductList(){
                this.selectLoading = true;
                const res = await getProductsInfo();
                this.selectLoading = false;
                if(res.data.code === 0){
                    let tempArr = [];
                    res.data.data.forEach(item => {
                        tempArr.push({
                            label: item.name,
                            value: item.id,
                            upsName: item.upsName,
                            businessName: item.businessName
                        });
                    });
                    this.productsList = tempArr;
                }else {
                    this.productsList = [];
                }     
            }
        }
    }
}